from xml.dom.minidom import parseString
import os
import sys

def getTrackMessage(content):
  parse=parseString(content)
  message=''
  error=''
  errors=parse.getElementsByTagName('error')
  print errors
  if errors:
    for node in errors[0].childNodes:
      if node.nodeType == node.TEXT_NODE:
        error= node.data.strip()
        break
  if error=='1':
    messages=parse.getElementsByTagName('message')
    if messages:
      for node in messages[0].childNodes:
        if node.nodeType == node.TEXT_NODE:
          message= node.data
          break
    
  return message

def main():
  print getTrackMessage("""<?xml version="1.0" encoding="utf-8"?>
    <response>
    
      <error>1
      </error>
      <message>The error message</message>
    </response>
    """)
  
if __name__ == '__main__':
  main()
